package com.panshi.controller.sysUser;

import com.panshi.api.SystemUserApi;
import com.panshi.po.SystemUserPo;
import com.panshi.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@Slf4j
public class SysUserController {



    @Resource
    private SystemUserApi systemUserApi;

    @GetMapping("/sys/user-all")
    public String query(){

        return "sysUser/user-query";
    }

    @PostMapping("/sys/user-all")
    @ResponseBody
    public PageModel<SystemUserPo> queryAllSys(PageModel<SystemUserPo> pm){
        pm.init();
        log.info("pm ------------------------{}",pm);
        MybatisPlusPageVo pageVo = new MybatisPlusPageVo();
        pageVo.setCurrentPage(pm.getCurrentPage());
        pageVo.setPageSize(pm.getPageSize());
        List<SystemUserPo> list = systemUserApi.queryAll(pageVo).getData();
        log.info("list ------------------------{}",list);
        //总条数
        Integer count = systemUserApi.userTotal().getData();
        pm.setCount(count);
        pm.setList(list);
        return pm;
    }

    @PostMapping("/sys/user-vague/{vague}")
    @ResponseBody
    public PageModel<SystemUserPo> queryVague(PageModel<SystemUserPo> pm, @PathVariable String vague){
        pm.init();
        log.info("pm ------------------------{}",pm);
        SystemUserLikeQueryVo pageVo = new SystemUserLikeQueryVo();
        pageVo.setCurrentPage(pm.getCurrentPage());
        pageVo.setPageSize(pm.getPageSize());
        pageVo.setUsername(vague);
        List<SystemUserPo> list = systemUserApi.likeUserName(pageVo).getData();
        log.info("list ------------------------{}",list);

        Integer count = systemUserApi.likeNameTotal(vague).getData();
        pm.setCount(count);
        pm.setList(list);
        return pm;
    }

    @PostMapping("/sys/user-state/{state}")
    @ResponseBody
    public PageModel<SystemUserPo> queryState(PageModel<SystemUserPo> pm, @PathVariable Integer state){
        pm.init();
        log.info("pm ------------------------{}",pm);
        StateQuery pageVo = new StateQuery();
        pageVo.setCurrentPage(pm.getCurrentPage());
        pageVo.setPageSize(pm.getPageSize());
        pageVo.setState(state);
        List<SystemUserPo> list = systemUserApi.listStateUser(pageVo).getData();
        log.info("list ------------------------{}",list);

        pageVo.setCurrentPage(1);
        pageVo.setPageSize(100);
        Integer count = systemUserApi.stateCount(state).getData();
        pm.setCount(count);
        pm.setList(list);
        return pm;
    }

}
